package ioTest

import (
	"bufio"
	"io"
	"io/ioutil"
	"os"
)

func Read1(path string, blocksize int) {
	fi, err := os.Open(path)
	if err != nil {
		panic(err)
	}
	defer fi.Close()
	block := make([]byte, blocksize)
	i := 0
	for {
		i++
		n, err := fi.Read(block)
		if err != nil && err != io.EOF {
			panic(err)
		}
		if 0 == n {
			break
		}
	}
	//fmt.Println(i, blocksize)
}

func Read2(path string, blocksize int) {
	fi, err := os.Open(path)
	if err != nil {
		panic(err)
	}
	defer fi.Close()
	r := bufio.NewReader(fi)
	block := make([]byte, blocksize)
	i := 0
	for {
		i++
		n, err := r.Read(block)
		if err != nil && err != io.EOF {
			panic(err)
		}
		if 0 == n {
			break
		}
	}
	//fmt.Println(i)
}

func Read3(path string) {
	fi, err := os.Open(path)
	if err != nil {
		panic(err)
	}
	defer fi.Close()
	_, err = ioutil.ReadAll(fi)
}

func Read4(path string) {
	_, err := ioutil.ReadFile(path)
	if err != nil {
		panic(err)
	}
}
